package logiexport.paneles;

import logiexport.bd.App;
import logiexport.pojos.User;
import logiexport.wizard.BuyWizard;
import logiexport.wizard.WizardPage;

import org.apache.wicket.Session;
import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;


public class PanelLogin extends Panel {
	
	User u = new User ();
	
	App app = new App();
	
	//private final boolean cRS=false;
	
	
	

	public PanelLogin(String id) {
		super(id);
		// TODO Auto-generated constructor stub
		
		
		app.convert_md5("ABCD1234");
		
		Form<User> loginform =  new Form<User>("loginform",new CompoundPropertyModel(u)) {
			
			protected void onSubmit() {
				// Al hacer submit verifico que existe un usuario con ese password 
				
			    Session s1 = Session.get();	    
			    
				AuthenticatedWebSession session = AuthenticatedWebSession.get();

			    System.out.println("session "+session.getClass());
			    System.out.println("Nombre: "+u.getName()+" Pass: "+u.getPass());
			    
				
				if(session.signIn(u.getName() , u.getPass())) {   
					
					System.out.println("Pass correcto nos vamos a BuyWizard!");
					
					setResponsePage(new WizardPage(BuyWizard.class));
					
				}
					
				
				
				
				
				
				System.out.println("------Nombre"+u.getEmail()+" Empresa"+u.getEmpresa());
				
			
				
			}	
					
					
		};
			add(loginform);
			
			TextField<User> email =  new TextField<User>("email", new PropertyModel(u, "name"));
			PasswordTextField pass = new PasswordTextField("pass", new PropertyModel(u, "pass"));
			
			
			loginform.add(email);
			loginform.add(pass);
		
		 	Link l = new Link("registerlink"){
				public void onClick(){
					
					PanelRegister pregister = new PanelRegister(PanelLogin.this.getId());
					PanelLogin.this.replaceWith(pregister);
				}
			};
		
		add(l);
		
		// CheckBox crs = new CheckBox("cRS", new PropertyModel<Boolean>(this, "cRS"));
		
		 
		/*	 CheckBox crs = new CheckBox("cRS", new PropertyModel<Boolean>(this, "cRS")){
				 
			
				    protected boolean wantOnSelectionChangedNotifications() {
				    	System.out.println("Dentro del change valor: "+cRS);
				        return true;
				    }
				 
			 };
		
		 add(crs); */
		
	}
	
	


	

}
